package com.me.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate5.HibernateTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.me.entity.NewsRecords;

@Service
public class SingleCharMsgService {

	@Autowired
	HibernateTemplate hibernateTemplate;

	@Transactional()
	public void save(NewsRecords nr) {
		hibernateTemplate.save(nr);
	}

	@Transactional
	public void UpdateMsgStateById(NewsRecords nr) {
		hibernateTemplate.update(nr);
	}

	public List getMsgById(int id) {

		List list = hibernateTemplate.find("from NewsRecords where id=" + id);
		return list;
	}

	public List getNoReadMsgByUserId(int id) {
		List list = hibernateTemplate
				.find("select u.account,n.content,n.ctime,n.type from UserInfo u,NewsRecords n where u.id=n.suid and n.isread=0 and n.ruid="
						+ id);

		return list;
	}
	
	
	public List getNoReadByTwoId(int suid,int ruid){
		List list=hibernateTemplate.find("from NewsRecords where isread=0 and (suid="+suid+" and ruid="+ruid+" or ruid="+suid+" and suid="+ruid+")");
	return list;
	}
	
	
	public List getAllNoReadMsgByUserId(int id){
		List list=hibernateTemplate.find("from NewsRecords where ruid="+id);
		return list;
	}

}
